package graphicsExtended.panel;

import image.PixelImage;
import image.mapper.PixelImageMapper;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * Fully Tested: No
 * Fully Documented: No
 * Created: 29-May-2012
 * Last Updated: 29-May-2012
 *
 * @author Shimu Wu
 */
public class ImageMapperFrame extends JFrame implements Runnable{

    private final BufferedImage img;

    public ImageMapperFrame(int width, int height,
            PixelImageMapper mapper) {
        this.setSize(width, height);

        PixelImage pixelImg = new PixelImage(width, height);
        this.img = pixelImg.map(mapper).toBufferImage();
        this.getContentPane().add(new ImageMapperPanel(width, height));
    }

    public void run() {
        this.setVisible(true);
    }

    private class ImageMapperPanel extends JPanel {

        private ImageMapperPanel(int width, int height) {
            this.setSize(width, height);
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(img, 0, 0, null);
        }
    }
}
